#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# This program is free software; you can redistribute it and/or modify  
# it under the terms of the GNU General Public License as published by  
# the Free Software Foundation; either version 2 of the License, or     
# (at your option) any later version.                                   
#                                                                         
# A copy of the license can be found in the license.txt file supplied   
# with this software or at: http://www.gnu.org/copyleft/gpl.html       
#


class   Router(object) :

    def route(self, message, address_from) :
        '''route message to handlers

        @return id of handler in name list
        '''
        return 0
        ## route()

    def setHandlerNameList(self, name_list) :
        pass
        ## setHandlerNameList()

    ## class Router


class   RoundRobinRouter(Router) :
    def __init__(self) :
        self._handler_name_list = []
        self._round = len(self._handler_name_list)
        self._last_id = -1
        ## __init__()

    def setHandlerNameList(self, name_list) :
        self._handler_name_list = name_list[:]
        self._round = len(self._handler_name_list)
        ## setHandlerNameList()

    def route(self, message, address_from) :
        self._last_id += 1
        return self._last_id % self._round
        ## route()

    ## class RoundRobinRouter

